' If the SQL Statement was successfully placed into the command buffer then
' send the command to the server for execution.
ret = SqlExec(dbconn)
If ret = 1 Then
' The SqlResults function will wait until the function is complete on
' the server. A return of 1 indicates that the statement has been executed
' on the server
ret = SqlResults(dbconn)
If ret = 1 Then
' In the case of a delete there are no rows returned in the result set
' the SqlRows command will confirm that no rows were returned.
ret = SqlRows(dbconn)
If ret = 1 Then
MsgBox "This command should not return rows"
Else
If updflag = 1 Then
MsgBox "Information changed for au_id " & text1(0).Text
Else
If updflag = 2 Then
MsgBox "Information added for au_id " & text1(0).Text
Else
MsgBox "Information deleted for au_id " & text1(0).Text
End If
End If
End If
Else
process_no_rows = ret
Exit Function
End If
Else
process_no_rows = ret
End If
process_no_rows = 99
End Function
Sub show_author ()
lc = author_list.ListIndex
If lc = -1 Then
Exit Sub
End If
d$ = RTrim(Left(author_list.List(lc), 15))
' Once the author has been selected from the list of authors
' process a SQL Statement which will select all the fields
' from the authors table for the author selected from the list
' by using the where clause on the primary key of the table
' The checking the ret variable for 1 indicates a test for a
' success. If the ret variable contains a 0 then the function
' failed
ret = SqlCmd(dbconn, "select * from authors where au_id = " & Chr(34) & d$ & Chr$(34))
If ret = 1 Then
' If the command was accepted into the buffer in the statement above
' then send it to the server for execution. If there are syntax
' errors in the statement then they will be found in the SqlExec step
ret = SqlExec(dbconn)
If ret = 1 Then
' If the command syntax was correct the command will be executing at
' the server now. The next function is the SqlResults function. This
' function will return once the processing is complete on the server.
' If the SqlCmd function had been passed more than one SQL command then
' you must perform a SqlResults for each result set being sent back.
' The end of result sets will be indicated by a NOMORERESUTLS(2) return
' from SqlResults
ret = SqlResults(dbconn)
If ret = 1 Then
' Once the result set is available for processing each row needs to be
' retrieved. This is accomplished by calling SqlNextRow until the function
' returns NOMOREROWS(-2)
ret = SqlNextRow(dbconn)
While ret <> NOMOREROWS
' For each column in the result set we call the function SqlData to
' get the data returned for the column. The data returned is a string
' representation of the data in the result column. The data is right
' trimmed when returned.
For c% = 1 To 9
dat$ = SqlData(dbconn, c%)
text1(c% - 1).Text = dat$
Next
ret = SqlNextRow(dbconn)
Wend
End If
End If
End If
End Sub
Sub SQLVBXDB1_ERROR (Sqlconn As Integer, Severity As Integer, ErrorNum As Integer, OsError As Integer, ErrorStr As String, OsErrorStr As String, RetCode As Integer)
' This is a SQL Server callback routine
' When the server needs to inform the user of a error this callback is
' called. For example if the user tries to logon to a server which does
' not exist then the error message string (errorstr) will contain text
' indicating that a connection with the requested server cannot be made.
' It is also this routine which is called when syntax errors are discovered
' in SQL commands submitted for execution.
MsgBox ErrorStr
End Sub
Sub SQLVBXDB1_MESSAGE (Sqlconn As Integer, Message As Long, State As Integer, Severity As Integer, msgstr As String, ServerName As String, ProcName As String, LineNum As Integer)
' This is a SQL Server callback routine
' When the server needs to inform the user of a status change this callback is
' used. For example when the user changes databases using the SqlUse function
' this event procedure will be called and the message string (msgstr) will
' contain text indicating the new database name.
' The variable severity can be used to filter the messages so that only messages
' which need to be seen can be displayed to the user
MsgBox msgstr
End Sub
Sub Text1_KeyPress (index As Integer, keyascii As Integer)
If updflag = 0 Then
keyascii = 0
End If
End Sub
Sub updbut_Click ()
Dim sql As String
If updflag = 3 Then
GoTo dontcheck
End If
If text1(0).Text = "" Then
MsgBox "Author Id cannot be NULL"
Exit Sub
End If
If text1(1).Text = "" Then
MsgBox "Last name cannot be NULL"
Exit Sub
End If
If text1(2).Text = "" Then
MsgBox "First name cannot be NULL"
Exit Sub
End If
If text1(3).Text = "" Then
MsgBox "Phone # cannot be NULL"
Exit Sub
End If
dontcheck:
If updflag = 1 Then
' In this application if the updflag is set to 1 then we are modifing the
' data for a particular row in the table authors. The following code will
' create a SQL Statement to 'UPDATE' the authors table where the au_id field